package com.yuexun.dhdoctor.module.meeting.adapter;

import android.widget.AbsListView;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.meeting.bean.MeetingBeanDate;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

/**
 * Created by work-jx on 2016/11/15.
 */
public class MeetingAdapter extends KJAdapter<MeetingBeanDate> {

    public MeetingAdapter(AbsListView view, Collection<MeetingBeanDate> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder adapterHolder, MeetingBeanDate meetingBeanDate, boolean b) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date meetingDate = null;
        try {
            meetingDate = dateFormat.parse(meetingBeanDate.getStarttime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        adapterHolder.setText(R.id.tv_week,meetingBeanDate.getWeek());
        adapterHolder.setText(R.id.tv_snapshot_date,meetingDate == null ? "" : new SimpleDateFormat("MM月dd日").format(meetingDate));
        adapterHolder.setText(R.id.tv_meeting_theme,meetingBeanDate.getMeetingName());
        adapterHolder.setText(R.id.tv_meeting_location,"地点："+ meetingBeanDate.getRoomName());
//        adapterHolder.setText(R.id.tv_meeting_date,String.format("时间：", meetingBeanDate.getStarttime(), meetingBeanDate.getEndtime()));

        try {
            Date start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(meetingBeanDate.getStarttime());
            Date end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(meetingBeanDate.getEndtime());


            try {
                if(dateFormat.parse(meetingBeanDate.getStarttime()).equals(dateFormat.parse(meetingBeanDate.getEndtime()))){
                    adapterHolder.setText(R.id.tv_meeting_date,"时间："+
                            new SimpleDateFormat("MM-dd HH:mm").format(start)+ " - " + new SimpleDateFormat("HH:mm").format(end));
                }else{
                    adapterHolder.setText(R.id.tv_meeting_date,"时间："+
                            new SimpleDateFormat("MM-dd HH:mm").format(start)+ " - " +new SimpleDateFormat("MM-dd HH:mm").format(end));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

}
